<template>
    <div class="publicpageview">
        <div class="publicformview">
            <el-form :inline="true" :model="listQuery" size="mini" ref="searchForm" label-width="120px">
                <el-row :gutter="20">

                    <el-col :span="4">
                        <el-form-item label="申请单位名称：" prop="applicant">
                            <el-input v-model="listQuery.applicant"></el-input>
                        </el-form-item>
                    </el-col>

                    <el-col :span="4">
                        <el-form-item label="收款单位名称：" prop="namePayee">
                            <el-input v-model="listQuery.namePayee"></el-input>
                        </el-form-item>
                    </el-col>

                    <el-col :span="4">
                        <el-form-item label="申请日期：" prop="applicantDate">
                            <el-date-picker v-model="listQuery.applicantDate" type="date" placeholder="年/月/日">
                            </el-date-picker>
                        </el-form-item>
                    </el-col>
                    <!-- <el-col :span="4">
                        <el-form-item label="申请金额：" prop="keyword">
                            <el-input v-model="listQuery.keyword"></el-input>
                        </el-form-item>
                    </el-col> -->

                    <el-col :span="4">
                        <el-form-item label="监管流程状态：" prop="status">
                            <el-select v-model="listQuery.status" clearable>
                                <el-option label="待提交" :value="0" :key="0"></el-option>
                                <el-option label="待审核" :value="1" :key="1"></el-option>
                                <el-option label="审核不通过" :value="-1" :key="-1"></el-option>
                                <el-option label="审核通过" :value="2" :key="2"></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="4">
                        <div>
                            <el-button size="mini" type="primary" @click="handleSearch">查询</el-button>
                            <el-button size="mini" @click="resetForm('searchForm')">重置</el-button>
                        </div>
                    </el-col>
                </el-row>
            </el-form>
        </div>

        <div class="publitableview">
            <el-button type="primary" size="mini" @click="handleAddUser('add')">付款申请录入</el-button>
            <el-table :data="list" border fit highlight-current-row size="mini">
                <el-table-column align="center" label="申请流程编号" prop="id">
                </el-table-column>
                <el-table-column align="center" label="申请单位名称" prop="applicant">
                </el-table-column>
                <el-table-column align="center" label="收款单位名称" prop="namePayee">
                </el-table-column>

                <el-table-column align="center" label="收款单位代码" prop="codePayee">
                </el-table-column>


                <el-table-column align="center" label="收款开户行" prop="beneficiaryBank">
                </el-table-column>

                <el-table-column align="center" label="申请金额合计" prop="applicationAmount">
                </el-table-column>

                <el-table-column align="center" label="监管流程状态" prop="status">
                    <template slot-scope="scope">
                        {{scope.row.status == 0 ? '待提交' : scope.row.status == 1 ? '待审核' : scope.row.status == 2 ?
                        '审核通过': '审核不通过'}}
                    </template>
                </el-table-column>

                <el-table-column align="center" label="操作" width="270" fixed="right">
                    <template slot-scope="scope">
                        <el-button type="text" size="mini" @click="handleUpdate(scope.row, 'shenhe')"
                            v-if="scope.row.status == 1">审核</el-button>
                        <el-button type="text" size="mini" @click="handleUpdate(scope.row, 'tijiao')"
                            v-if="scope.row.status == 0">提交</el-button>
                        <el-button type="text" size="mini" @click="handleUpdate(scope.row, 'tuihui')"
                            v-if="scope.row.status == 2 || scope.row.status == 1">退回</el-button>
                        <el-button type="text" size="mini" @click="handleUpdate(scope.row, 'update')">修改</el-button>
                        <el-button type="text" size="mini" @click="handleUpdate(scope.row,'details')">详情</el-button>
                        <el-button type="text" size="mini" @click="handleDelete(scope.row.id)">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="publicpaginationview">
                <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
                    :current-page="listQuery.pageNum" background :page-sizes="[10, 20, 50, 100]"
                    :page-size="listQuery.pageSize" layout="total, sizes, prev, pager, next, jumper" :total="total"
                    small></el-pagination>
            </div>
        </div>


    </div>
</template>

<script>

import { listRepairFundsSupervision, deleteRepairFundsSupervision, submitOrBackRepairFundsSupervision } from '@/api/repair'
import { Message } from 'element-ui'
export default {
    name: "AccommodationManagementIndex",

    data() {
        return {
            listQuery: {
                pageNum: 1,
                pageSize: 10,
                applicant: "",
                status: null,
                applicantDate: "",
                namePayee: ""
            },


            total: 0,

            list: [

            ],
        };
    },

    computed: {

    },

    mounted() {
        this.getList();




    },


    methods: {



        handleSizeChange(val) {
            this.listQuery.pageNum = 1;
            this.listQuery.pageSize = val;
            this.getList();
        },
        handleCurrentChange(val) {
            this.listQuery.pageNum = val;
            this.getList();
        },

        handleSearch() {
            this.listQuery.pageNum = 1;
            this.getList();
        },
        getList() {
            listRepairFundsSupervision(this.listQuery).then((response) => {
                this.list = response.data.list;
                this.total = response.data.total;
            });
        },





        resetForm(val) {

            this.$refs[val].resetFields();
            this.listQuery.pageNum = 1;
        },

        handleAddUser(type) {
            if (type == 'add') {
                this.$router.push({
                    path: 'xiushanjingfeijianguanAdd',
                    query: {
                        type: 'add',
                    }
                })
            }
        },


        handleUpdate(currentData, type) {

            if (type == 'shenhe' || type == 'update' || type == 'details') {
                this.$router.push({
                    path: 'xiushanjingfeijianguanAdd',
                    query: {
                        type,
                        id: currentData.id
                    }
                })
            }

            if (type == 'tijiao') {

                let formdata = new FormData();
                formdata.append('status', 1);
                formdata.append("id", currentData.id)

                this.$confirm(
                    "请确认是否提交此条修缮经费",
                    "提示",
                    {
                        confirmButtonText: "确 认",
                        cancelButtonText: "取 消",
                        type: "warning",
                    }
                )
                    .then(() => {
                        console.log('1')
                        submitOrBackRepairFundsSupervision(formdata).then(res => {
                            this.$message.success("操作成功");
                            this.getList()
                        })
                    })
                    .catch(() => { });
            }


            if (type == 'tuihui') {
                let formdata = new FormData();
                formdata.append('status', 0);
                formdata.append("id", currentData.id)

                this.$confirm(
                    "请确认是否退回此条修缮经费",
                    "提示",
                    {
                        confirmButtonText: "确 认",
                        cancelButtonText: "取 消",
                        type: "warning",
                    }
                )
                    .then(() => {
                        submitOrBackRepairFundsSupervision(formdata).then(res => {
                            this.$message.success("操作成功");
                            this.getList()
                        })
                    })
                    .catch(() => { });
            }

        },

        handleDelete(id) {
            this.$confirm(
                "此操作将删除该条内容，请确认是否继续操作？",
                "删除提示",
                {
                    confirmButtonText: "保 存",
                    cancelButtonText: "取 消",
                    type: "warning",
                }
            )
                .then(() => {
                    deleteRepairFundsSupervision(id).then(res => {
                        this.$message.success("操作成功");
                        this.getList()
                    })
                })
                .catch(() => { });
        }
    },
};
</script>

<style scoped>
.el-date-editor.el-input {
    width: 100%;
    cursor: pointer;
}
</style>